/**
 * Project:   warnme-app
 * File:      UpdateRestClientOnPreferenceChangeListener.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      Mar 27, 2014
 */

package dtu.ds.warnme.app.ws.client.restful;

import org.apache.commons.lang3.StringUtils;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import dtu.ds.warnme.app.application.Prefs;

/**
 * @author Bartosz Cichecki
 * 
 */
public class UpdateRestClientOnPreferenceChangeListener implements OnSharedPreferenceChangeListener {

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		if (StringUtils.equals(key, Prefs.Keys.SERVER_HOST) || StringUtils.equals(key, Prefs.Keys.SERVER_PORT)
		        || StringUtils.equals(key, Prefs.Keys.USER_USERNAME) || StringUtils.equals(key, Prefs.Keys.USER_PASSWORD_HASH)
		        || StringUtils.equals(key, Prefs.Keys.SERVER_REALM)) {
			RestClientHolder.updateRestClient();
		}

	}

}
